var curry = function (fn) {
  var _args = [];
  console.log("curry");
  return function cb() {
    console.log("_args.length", _args.length);
    if (arguments.length === 0) {
      return fn.apply(this, _args)
    }
    Array.prototype.push.apply(_args, arguments);//_args.push(arguments)
    return cb;
  }
};

function add(...args) {
  let sum = 0;
  for (let i = 0; i < args.length; i++) {
    sum += args[i];
  }
  return sum;
}

let cAdd = curry(add);
let message = cAdd(1)(2)(4)();
console.log(message);
// let message1 = message(3);
// let message2 = message1(9);
// let message3 = message2();
// console.log(message3);
